package com.tian.controller;

import com.tian.annotation.SysLogAnnotation;
import com.tian.config.MessageTemplateSingleton;
import com.tian.dto.TestDto;
import com.tian.enums.SysLogTypeEnum;
import com.tian.util.CommonResult;
import com.tian.util.ParamValidate;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;

/**
 * @author tianwc  公众号：java后端技术全栈、面试专栏
 * @version 1.0.0
 * @date 2023年06月05日 16:01
 * 博客地址：<a href="http://woaijava.cc/">博客地址</a>
 */
@Slf4j
@RestController
@RequestMapping("/test")
public class TestController {

    @Resource
    private MessageTemplateSingleton messageTemplateSingleton;

    @GetMapping("/index1")
    public CommonResult<MessageTemplateSingleton.Template> index() {
        ParamValidate.isNull(null, "参数为空");
        MessageTemplateSingleton.Template template = messageTemplateSingleton.getTemplate(1);
        return CommonResult.success(template);
    }

    @SysLogAnnotation(methodDescription = "测试",type = SysLogTypeEnum.DB)
    @PostMapping("/index2")
    public CommonResult<MessageTemplateSingleton.Template> index2(@RequestBody @Valid TestDto testDto) {
        log.info("入参={}", testDto);
        MessageTemplateSingleton.Template template = messageTemplateSingleton.getTemplate(1);
        return CommonResult.success(template);
    }
}
